//
//  ViewController.m
//  MoviePlayer
//
//  Created by student on 16/4/5.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "ViewController.h"
#import <MediaPlayer/MediaPlayer.h>
@interface ViewController ()

@property(nonatomic,strong)MPMoviePlayerViewController *moviePlayerVC;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)btnPressed:(id)sender
{
    //打包中的文件 沙盒中的 网络上
    NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"Movie" withExtension:@"m4v"];
//    [NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"background" ofType:@"mov"]];
    
    //创建播放视图控制器
    self.moviePlayerVC = [[MPMoviePlayerViewController alloc]initWithContentURL:fileURL];
        //事故多发点    //^
    
    
    
    //1.弹出方式
    //样式
    self.moviePlayerVC.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
    //缩放模式
    self.moviePlayerVC.moviePlayer.scalingMode = MPMovieScalingModeFill;
    //弹出
    [self presentMoviePlayerViewControllerAnimated:self.moviePlayerVC];
    
    //2.嵌入当前页面
//    self.moviePlayerVC.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;//嵌入方式
//    self.moviePlayerVC.moviePlayer.scalingMode = MPMovieScalingModeNone;
//    self.moviePlayerVC.view.frame = CGRectMake(0, 100, 320, 200);
//    [self.view addSubview:self.moviePlayerVC.view];
    
    //监听播放器（播放完成）的通知
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(playDone) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
    
    //播放
    [self.moviePlayerVC.moviePlayer play];
}
-(void)playDone
{
    NSLog(@"播放完毕，关闭播放器");
    
    [self dismissMoviePlayerViewControllerAnimated];
}

@end
